exports.buildTree = function (list, idKey, parentIdKey, childrenKey) {
    let node = {};
    for(let i = 0; i< list.length; ++i) {
        node[list[i][idKey]] = list[i];
    }

    let result = [];
    for (let i = 0; i < list.length; ++i) {
        let n = list[i];
        let pNode = node[ n[parentIdKey] ];
        if (pNode) {
            if (!pNode[childrenKey]) pNode[childrenKey] = [];
            pNode[childrenKey].push(n);
        }else {
            result.push(n);
        }
    }
    return result;
}
